import { AstContext } from "../../../context";
import { Pages } from "../Pages";
import { PageVisitor } from "../pageVisitor";
import { currentPage } from "./consts";
import { createToIndex } from "./createToIndex";
import { createToTitle } from "./createToTitle";
export interface BottomBarContext {
    toBottomTab: (index: number) => boolean;
    toBottomTabTitle: (title: string) => boolean;
    bottomTabIndex: number;
    bottomTab: string;
}
// visitFrameLayout R.bottom_bar_and_grey_cover_container
// 推荐排序|时间排序|只看朋友 关注下拉选择框
export function parseBottomBarAndGreyCoverContainer(visitor: PageVisitor, ast: AutoJs.UiObject, ctx: AstContext): boolean {
    const scrollView = ctx.bfsOne(ast, (node) => {
        return node.className() === `android.widget.HorizontalScrollView` && ctx.getSid(node) === `tab_layout` && node.visibleToUser()
    })
    if (scrollView) {
        const node = ctx.bfsOne(scrollView, it => it.childCount() === 4)
        if (!node) return true;
        ctx.set(`toBottomTab`, createToIndex(node, ctx, 'bottomTabIndex'))
        ctx.set(`toBottomTabTitle`, createToTitle(node, ctx, 'bottomTab'))
        ctx.eachChild(node, (it, index) => {
            const selected = it.selected()
            if (selected) {
                const text = ctx.getText(it)
                switch (text) {
                    case '我':
                        ctx.set(currentPage, Pages.mine)
                        break;
                    case '消息':
                        ctx.set(currentPage, Pages.message)
                        break;
                    case '精选':
                        ctx.set(currentPage, Pages.jingxuan)
                        break;
                    default:
                        break;
                }
                ctx.set('bottomTabIndex', index)
                ctx.set('bottomTab', text)
            }
        })
    }
    return true;
}
